<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head th:replace="~{segmentation/_right_bottom_header::_header_common(~{::title},~{::link},~{::style})}">
    <meta charset="utf-8">
    <title>用户编辑</title>
    <link>
    <style type="text/css"></style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>用户编辑</legend>
        </fieldset>
        <form class="layui-form" id="userFormEdit" action="">
            <input type="hidden" id="id" name="id" th:value="${p.id}"/>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>帐号</label>
                <div class="layui-input-block">
                    <span class="view-span" th:text="${p.account}"></span>
                </div>
            </div>
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>密码-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="password" name="password" id="password" lay-verify="password"-->
<!--                           lay-verType="tips"-->
<!--                           placeholder="需要修改密码在填写，不修改密码无须填写!" autocomplete="off" class="layui-input">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>确认密码-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="password" name="confirmPassword" id="confirmPassword" lay-verify="confirmPassword"-->
<!--                           lay-verType="tips"-->
<!--                           placeholder="需要修改密码在填写，不修改密码无须填写!" autocomplete="off" class="layui-input">-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required|name"
                           lay-verType="tips"
                           th:value="${p.name}"
                           placeholder="请输入姓名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>电话</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" lay-verify="required|phone|telphone"
                           lay-verType="tips"
                           th:value="${p.phone}"
                           placeholder="请输入电话" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>邮箱</label>
                <div class="layui-input-block">
                    <input type="text" name="email" lay-verify="required|email|myEmail"
                           lay-verType="tips"
                           th:value="${p.email}"
                           placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label"><span class="required-red">*</span>启用状态</label>
                <div class="layui-input-block">
                    <input th:each="item : ${@typeServiceImpl.findByParentCodeList('enableStatus')}"
                           th:title="${item.typeName}"
                           th:value="${item.typeValue}"
                           th:checked="${p.enableStatus == item.typeValue}"
                           type="radio" name="enableStatus" lay-verify="required|enableStatus"
                           lay-verType="tips">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>级别</label>
                <div class="layui-input-block">
                    <input type="text" name="userLevel" lay-verify="required|userLevel"
                           lay-verType="tips"
                           onchange="this.value=this.value.replace(/\D/g,'')"
                           onkeyup="this.value=this.value.replace(/\D/g,'')"
                           onafterpaste="this.value=this.value.replace(/\D/g,'')"
                           th:value="${p.userLevel}"
                           placeholder="请输入级别" autocomplete="off" class="layui-input">
                </div>
            </div>
<!--            <div class="layui-form-item" pane="">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>是否锁住-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="radio" name="accountLocked" lay-verify="required|accountLocked"-->
<!--                           lay-verType="tips"-->
<!--                           value="2" title="是" th:checked="${p.accountLocked == 2}">-->
<!--                    <input type="radio" name="accountLocked" lay-verify="required|accountLocked"-->
<!--                           lay-verType="tips"-->
<!--                           value="1" title="否" th:checked="${p.accountLocked == 1}">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="layui-form-item" pane="">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>帐号是否过期-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="radio" name="accountExpired" lay-verify="required|accountExpired"-->
<!--                           lay-verType="tips"-->
<!--                           value="2" title="是" th:checked="${p.accountExpired == 2}">-->
<!--                    <input type="radio" name="accountExpired" lay-verify="required|accountExpired"-->
<!--                           lay-verType="tips"-->
<!--                           value="1" title="否" th:checked="${p.accountExpired == 1}">-->
<!--                </div>-->
<!--            </div>-->
<!--            <div class="layui-form-item" pane="">-->
<!--                <label class="layui-form-label"><span class="required-red">*</span>凭证是否过期-->
<!--                </label>-->
<!--                <div class="layui-input-block">-->
<!--                    <input type="radio" name="credentialsExpired" lay-verify="required|credentialsExpired"-->
<!--                           lay-verType="tips"-->
<!--                           value="2" title="是" th:checked="${p.credentialsExpired == 2}">-->
<!--                    <input type="radio" name="credentialsExpired" lay-verify="required|credentialsExpired"-->
<!--                           lay-verType="tips"-->
<!--                           value="1" title="否" th:checked="${p.credentialsExpired == 1}">-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入描述" autocomplete="off" lay-verify="description"
                              lay-verType="tips"
                              th:text="${p.description}"
                              name="description" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item custom-text-align"
                 sec:authorize="hasPermission(#authorization.authentication,'button','SYSTEM_USER_LIST_MANAGEMENT:edit')">
                <a class="layui-btn" lay-submit="" lay-filter="userFormEditSubmit">保存</a>
            </div>
        </form>
    </div>
</div>

<div th:replace="~{segmentation/_tail::_tail_common}"></div>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script th:inline="javascript">
    /*<![CDATA[*/
    [# sec:authorize = "hasPermission(#authorization.authentication,'button','SYSTEM_USER_LIST_MANAGEMENT:edit')"]
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;
        var regPhone =
            /^((\+86|0086)?\s*)((134[0-8]\d{7})|(((13([0-3]|[5-9]))|(14[5-9])|15([0-3]|[5-9])|(16(2|[5-7]))|17([0-3]|[5-8])|18[0-9]|19(1|[8-9]))\d{8})|(14(0|1|4)0\d{7})|(1740([0-5]|[6-9]|[10-12])\d{7}))$/;
        var regEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
        //自定义验证规则
        form.verify({
            // password: function (value) {
            //     if (!value) {
            //         return;
            //     }
            //     if (value.length < 6 || value.length > 25) {
            //         return '密码最少6个字符或最多25个字符';
            //     }
            // },
            // confirmPassword: function (value) {
            //     if (!value) {
            //         return;
            //     }
            //     if ($("#password").val() != value) {
            //         return '请输入相同密码';
            //     }
            // },
            name: function (value) {
                if (value.length > 20) {
                    return '姓名最多20个字符';
                }
            },
            telphone: function (value) {
                if (value.length > 20) {
                    return '电话最多20个字符';
                }
                //自定义验证规则
                if (!regPhone.test(value)) {
                    return "请输入正确手机号码!";
                }
            },
            myEmail: function (value) {
                if (value.length > 32) {
                    return '邮箱最多32个字符';
                }
                //自定义验证规则
                if (!regEmail.test(value)) {
                    return "请输入正确邮箱!";
                }
            },
            enableStatus: function (value) {
            },
            [# sec:authorize="hasPermission(#authorization.authentication,'button','SYSTEM_USER_LIST_MANAGEMENT:level')"]
            userLevel: function (value) {
                if (value.length > 7) {
                    return '级别最多7个字符';
                }
            },
            [/]
            // accountLocked: function (value) {
            // },
            description: function (value) {
                if (!value) {
                    return;
                }
                if (value.length > 1000) {
                    return '描述最多1000个字符';
                }
            }
        });

        //监听提交
        form.on('submit(userFormEditSubmit)', function (data) {
            $.ajax({
                type: 'POST',
                url: '/system/user/edit',
                data: data.field,
                dataType: 'json',
                success: function (data) {
                    if (data.code == Result.SUCCESS) {
                        layer.msg('成功!', {
                            icon: 1,
                            shade: [0.3, '#f5f5f5'],
                            time: 1500
                        }, function () {
                            $("#userList", window.parent.document).attr('value', 1);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 3000
                        });
                    }
                }
                /* error:function(data) {
                    console.log(data.msg);
                }, */
            });
            return false;//返回false防止重复提交
        });
    });
    [/]
    /*]]>*/
</script>

</body>
</html>